// pages/fb_detail/fb_detail.js
import tool from '../../modules/tool'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    item: undefined,
    loadingImage: true,
  },

  handleShowUserMyPage() {
    tool.handleShowFBMyPage(this.data.item.openId, this.data.item.openId_read)
  },

  handleDeleteOrWithdraw() {
    if (this.data.item.per.delete) {
      this.handleDelete()
      return
    }
    this.handleWithDraw()
  },

  handleWithDraw() {
    tool.feedback.delete(this.data.item.id, () => {
      wx.navigateBack()
    }, false)
  },

  handleCreateChatRoom() {
    tool.handleShowModel('是否开启聊天室？', true, () => {
      tool.chatRoom.create(this.data.item.openId, this.data.item.id)
    })

  },

  handleDelete() {
    tool.feedback.delete(this.data.item.id, () => {
      wx.navigateBack()
    }, true)
  },

  handleBack() {
    wx.navigateBack()
  },

  handleAnswer() {
    tool.feedback.answer(this.data.item.id, (item) => {
      this.setData({
        item
      })
      wx.navigateBack()
    })
  },

  loadedImage() {
    this.setData({
      loadingImage: false
    })
  },

  handlePreview() {
    wx.previewImage({
      urls: [this.data.imagePrefix + this.data.item.image],
    })
  },

  handlePreviewLocation() {
    wx.openLocation({
      latitude: parseFloat(this.data.item.location1),
      longitude: parseFloat(this.data.item.location2),
    })
  },

  handleCall() {
    wx.makePhoneCall({
      phoneNumber: this.data.item.phone,
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    tool.setPageData(this)
    let data = tool.store.getItem('feedBack_detail')
    tool.store.removeItem('feedBack_detail')
    if (data === undefined) {
      wx.navigateBack()
      return
    }
    this.setData({
      item: data
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})